<template>
	<view class="page">
		<!-- 地址 -->
		<view class="address-data" v-if="buy_shop_switch==2">
			<view class="address-list" @tap='onAddress'>
				<view  v-if="addressInfo">
					<view class="list">
						<text>{{addressInfo.province}}{{addressInfo.city}}{{addressInfo.area}}</text>
					</view>
					<view class="list">
						<text class="address">{{addressInfo.address}}</text>
					</view>
					<view class="list">
						<text>{{addressInfo.name}}</text>
						<text>{{addressInfo.phone}}</text>
					</view>
					<view class="list">
						<text class="tips">(如果快递不方便接收，您可以选择暂时寄存服务)</text>
					</view>
				</view>
				<view class="flex flex-align flex-bt" v-else style="padding-bottom: 30rpx;">
					<view class="left" >设置收货地址</view>
					<view class="rigth">
						<tui-icon name="arrowright" :size="24" color="#999"></tui-icon>
					</view>
				</view>
			</view>
			<view class="bar">

			</view>
		</view>
		<view class="ziti" v-else>
			<view class="title">
				<text>社区自提</text>
			</view>
			<view class="zitiList">
				<view class="list flex flex-align">
					<view class="left">提货人</view>
					<view class="inpt"><input type="text" placeholder="请输入提货人" v-model="name" :disabled="isName" /></view>
				</view>
				<view class="list flex flex-align">
					<view class="left">手机号码</view>
					<view class="inpt"><input type="number" placeholder="请输入手机号码" v-model="phone" :disabled="isPhone" /></view>
				</view>
				<view class="lists">
					团长信息：{{dataInfos.name||'请联系管理员'}}
				</view>
				<view class="lists">
					提货地点：{{dataInfos.address||'请联系管理员'}}
				</view>
			</view>
		</view>
		<!-- 商品 -->
		<view class="goods-data">
			<view class="goods-title">
				<text>商品信息</text>
			</view>
			<view class="goods-list">
				<view class="list" v-for="(item,index) in order" :key="index">
					<view class="thumb">
						<image :src="item.goods_cover" mode=""></image>
					</view>
					<view class="item">
						<view class="title">
							<text class="name one-omit">{{item.goods_name}}</text>
							<text class="attr" style="margin-top: 10rpx;">{{item.goods_spec}}</text>
						</view>
						<view class="price-number">
							<!-- <view class="price">
								<text class="min">￥</text>
								<text class="max">{{item.price_selling}}</text>
							</view> -->
							<view class="price" v-if="dataInfo.goods_type!=3&&dataInfo.goods_type!=4">
								<text class="min">￥</text>
								<text class="max">{{item.price_selling}}<text style="color: #f20;" v-if="dataInfo.balance2!=0">+{{dataInfo.balance2}}<text style="font-size: 24rpx;">礼品卡</text></text></text>
							</view>
							<view class="price" v-if="dataInfo.goods_type==3">
								<text class="max">{{Math.trunc(item.price_selling)}}</text><text style="color: #f20;margin-left: 10rpx;font-weight: 700;">礼品卡</text>
							</view>
							<view class="price" v-if="dataInfo.goods_type==4">
								<text class="max" v-if="item.price_selling!=0">{{item.price_selling}}+</text><text class="max">{{Math.trunc(item.balance3)}}</text><text style="color: #f20;margin-left: 10rpx;font-weight: 700;">红包券</text>
							</view>
							<view class="number">
								<text>x {{item.stock_sales}}</text>
							</view>
						</view>
						<!-- <view class="tag">
							<text>支持七天无理由退货</text>
						</view> -->
					</view>
				</view>
			</view>
			<view class="delivery">
				<div class="list">
					<view class="title">配送</view>
					<view class="content">
						<text>{{buy_shop_switch==2?'快递运输':'自提'}}</text>
						<text class="iconfont icon-more"></text>
					</view>
				</div>
				<div class="list">
					<view class="title">留言</view>
					<view class="content">
						<input type="text" placeholder="选填,建议先和商家沟通确认" style="width: 400rpx;">
					</view>
				</div>
			</view>
		</view>
		<!-- 优惠 -->
		
		<!-- 订单金额 -->
		<view class="order-price">
			<view class="price-list">
				<view class="list">
					<view class="title">
						<text>商品金额</text>
					</view>
					<view class="price" v-if="dataInfo.goods_type!=3&&dataInfo.goods_type!=4">
						<text class="min">￥</text>
						<text class="max">{{dataInfo.amount_total}}<text  v-if="dataInfo.balance2!=0">+{{dataInfo.balance2}}<text style="font-size: 24rpx;">礼品卡</text></text></text>
					</view>
					<view class="price" v-if="dataInfo.goods_type==3">
						<text class="max">{{Math.trunc(dataInfo.amount_total)}}</text><text style="margin-left: 10rpx;font-weight: 700;font-size: 24rpx;">礼品卡</text>
					</view>
					<view class="price" v-if="dataInfo.goods_type==4">
						<text class="max" v-if="dataInfo.amount_total!=0">{{dataInfo.amount_total}}+</text><text class="max">{{Math.trunc(dataInfo.balance3)}}</text><text style="margin-left: 10rpx;font-weight: 700;font-size: 24rpx;">红包券</text>
					</view>
				</view>
				<view class="list" @click="openQuan" v-if="quanInfo.length!=0&&overlay_coupon!=3">
					<view class="title">
						<text>优惠券</text>
					</view>
					<view class="price">
						<text style="color: #f20;">{{yhqInfo}}</text>
					</view>
				</view>
				<view class="list" @click="openQuanY" v-if="quanInfoY.length!=0">
					<view class="title">
						<text>指定优惠券</text>
					</view>
					<view class="price">
						<text style="color: #f20;">{{yhqInfoY}}</text>
					</view>
				</view>
				<view class="list" v-if="overlay_coupon==3">
					<view class="title">
						<text>优惠券</text>
					</view>
					<view class="price">
						<text style="color: #f20;">- ￥{{dataInfo.coupon_price}}</text>
					</view>
				</view>
				<view class="list" v-if="overlay_couponY==3&&extra_coupon_price!=0" @click="getischeck">
					<view class="title flex flex-align">
						<checkbox backgroundColor="#fe3b0f" style="transform: scale(.7);margin-right: 10rpx;" value="cb" :checked="!ischeck" />
						<text>指定优惠券</text>
					</view>
					<view class="price">
						<text style="color: #f20;">- ￥{{extra_price}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 底部合计提交 -->
		<view class="footer-submit">
			<view class="price" v-if="dataInfo.goods_type!=3&&dataInfo.goods_type!=4">
				<text class="min">￥</text>
				<text class="max">{{count}}<text style="color: #f20;" v-if="dataInfo.balance2!=0">+{{dataInfo.balance2}}<text style="font-size: 24rpx;">礼品卡</text></text></text>
			</view>
			<view class="price" v-if="dataInfo.goods_type==3">
				<text class="max">{{Math.trunc(dataInfo.amount_real)}}</text><text style="color: #f20;margin-left: 10rpx;font-weight: 700;">礼品卡</text>
			</view>
			<view class="price" v-if="dataInfo.goods_type==4">
				<text class="max" v-if="dataInfo.amount_total!=0">{{dataInfo.amount_total}}+</text><text class="max">{{Math.trunc(dataInfo.balance3)}}</text><text style="color: #f20;margin-left: 10rpx;font-weight: 700;">红包券</text>
			</view>
			<view class="submit" @click="onSubmit">
				<text>提交订单</text>
			</view>
		</view>
		<!-- 发票 -->
		<!-- 优惠券 -->
		<!-- 优惠券 -->
		<view class="page-total">
			<view class="cu-modal bottom-modal" :class="{ show: isShow }" @click="hide()">
				<view class="cu-dialog">
					<view class="coupon-tab flex flex-center">
						<view class="tab action">
							<text>可用优惠券</text>
							<text class="line"></text>
						</view>
					</view>
					<!-- 优惠券数据 -->
					<view class="coupon-data">
						<view class="coupon-list">
							<scroll-view scroll-y="true" style="max-height: 700rpx;padding-bottom: 30rpx;">
								<view class="list" v-for="(item,index) in quanInfo" :key="index" @click.stop="onTab(item,index)">
									<view class="coupon-price">
										<view class="discounts">
											<text class="min">￥</text>
											<text class="max">{{item.price}}</text>
										</view>
										<view class="full-reduction"><text>满{{item.full_price}}元减{{item.price}}元</text></view>
										<view class="jag"></view>
									</view>
									<view class="coupon-info">
										<view class="check">
											<tui-icon :color="item.checked?'#f20':''" :name="item.checked?'circle-fill':'circle'" :size="20"></tui-icon>
										</view>
										<view class="info-title">
											<view class="tag">
												<text>限品类券</text>
											</view>
											<view class="title">
												<text>仅可购买会员专区商品</text>
											</view>
										</view>
										<view class="date-get">
											<view class="date">
												<text>结束时间:{{item.end_time}}</text>
											</view>
											<!-- <view class="get">
												<text>点击领取</text>
											</view> -->
										</view>
									</view>
								</view>
							</scroll-view>
							
						</view>
					</view>
					<!--确认 -->
					<view class="cpupon-confirm">
						<view class="confirm" @click.stop="onConfirm">确定</view>
					</view>
				</view>
			</view>
		</view>
		<view class="page-total">
			<view class="cu-modal bottom-modal" :class="{ show: isShowY }" @click="hide()">
				<view class="cu-dialog">
					<view class="coupon-tab flex flex-center">
						<view class="tab action">
							<text>可用指定优惠券</text>
							<text class="line"></text>
						</view>
					</view>
					<!-- 优惠券数据 -->
					<view class="coupon-data">
						<view class="coupon-list">
							<scroll-view scroll-y="true" style="max-height: 700rpx;padding-bottom: 30rpx;">
								<view class="list" v-for="(item,index) in quanInfoY" :key="index" @click.stop="onTabY(item,index)">
									<view class="coupon-price">
										<view class="discounts">
											<text class="min">￥</text>
											<text class="max">{{item.price}}</text>
										</view>
										<view class="full-reduction"><text>满{{item.full_price}}元减{{item.price}}元</text></view>
										<view class="jag"></view>
									</view>
									<view class="coupon-info">
										<view class="check">
											<view :class="item.checked?'iconfont icon-checked':'iconfont icon-check'"></view>
										</view>
										<view class="info-title">
											<view class="tag">
												<text>限品类券</text>
											</view>
											<view class="title">
												<text>仅可购买会员专区商品</text>
											</view>
										</view>
										<view class="date-get">
											<view class="date">
												<text>结束时间:{{item.end_time}}</text>
											</view>
											<!-- <view class="get">
												<text>点击领取</text>
											</view> -->
										</view>
									</view>
								</view>
							</scroll-view>
							
						</view>
					</view>
					<!--确认 -->
					<view class="cpupon-confirm">
						<view class="confirm" @click.stop="onConfirmY">确定</view>
					</view>
				</view>
			</view>
		</view>
		<view class="" style="height: 100rpx;"></view>
		<!-- <use-coupon ref="UseCoupon" :data="quanInfo" @finish="getyhq"></use-coupon> -->
		<!-- <view class="flex flex-align flex-center zhezhao" v-if="isloading">
			<loading></loading>
		</view> -->
		<tui-modal :show="modal" @click="handleClick" @cancel="modal=false" title="提示" content="是否已完成支付？"></tui-modal>
	</view>
</template>

<script>
	import UseCoupon from '../../components/UseCoupon/UseCoupon.vue'
	// import loading from "@/components/loadings/loadings.vue"
	// import GoEasy from '@/uni_modules/goeasy-js/js_sdk/goeasy-2.12.4.esm.min.js';
	export default {
		components: {
			// 优惠券
			UseCoupon,
			// loading
		},
		data() {
			return {
				scrollTop: 0,
				addressInfo:'',
				code:'',
				dataInfo:'',
				order:[],
				quanInfo:[],
				quanInfoY:[],
				yhqContent:'',
				yhqContentY:'',
				yhqInfo:'请选择优惠券',
				yhqInfoY:'请选择指定优惠券',
				count:0,
				buy_shop_switch:'',
				dataInfos:'',
				name:'',
				phone:'',
				type:'',
				isName:false,
				isBtn:false,
				userId:'',
				pay_switch:'',
				isShow:false,
				isShowY:false,
				overlay_coupon:'',
				isPhone:false,
				userinfo:'',
				modal:false,
				coupon_price_max:'',
				prices:0,
				overlay_couponY:'',
				coupon_price_maxY:'',
				priceY:0,
				extra_coupon_price:'',
				ischeck:false,
				extra_price:0,
			};
		},
		onPageScroll(e){
			this.scrollTop = e.scrollTop;
			this.type=e.type
		},
		onLoad(e) {
			this.code =e.order_no
			// uni.setStorageSync('isZhifu','')
		},
		onShow() {
			let that = this
			this.get_data()
			this.getData()
			this.yhqContent = ''
			this.yhqInfo='请选择优惠券'
			this.coupon_price_max = ''
			this.quanInfo = ''
			this.prices = 0
			this.ischeck = true
			this.extra_price = 0
			uni.$on('isbtn', function(data) {
				that.isBtn = false
			});
			// "N6000012296929164555"
			// uni.setStorageSync('isZhifu',"N6000101305414081563")
			if(uni.getStorageSync('isZhifu')){
				// setTimeout(function(){
				// 	that.getStatus()
				// },1000)
				that.modal = true
				
			}
		},
		onUnload() {
			/** 这里只保留最新的15条会话记录，以保证初次加载性能 */
			uni.$off('isbtn');
		},
		onHide() {
			uni.$off('isbtn');
		},
		methods:{
			/**
			 * 提交订单
			 */
			hide(){
				this.isShow = false
			},
			handleClick(e){
				let index = e.index;
				if (index === 0) {
					uni.setStorageSync('isZhifu',"")
				} else {
					if(this.pay_switch==6){
						this.getStatus1(uni.getStorageSync('isZhifu'))
					}else if(this.pay_switch==5){
						this.getStatus()
					}
				}
				this.modal = false
				this.isBtn = false
			},
			getischeck(){
				let that = this
				that.ischeck = !that.ischeck
				that.getCount()
			},
			getCount(){
				let that = this
				let dataCount = 0
				let price = 0
				that.quanInfo.map((item,index)=>{
					if(item.checked){
						price = Number(price)+Number(item.price)
					}
				})
				if(that.ischeck){
					that.count = (Number(that.dataInfo.amount_total)- Number(price)-Number(that.extra_coupon_price)).toFixed(2)
					if(that.count<0){
						that.count = 0
						that.yhqInfo ="-"+(Number(that.dataInfo.amount_total)- Number(that.extra_coupon_price)).toFixed(2)+"元"
					}
					that.extra_price = Number(that.extra_coupon_price)
				}else{
					if(Number(that.dataInfo.amount_total)- Number(price)<=0){
						that.count = 0
						that.yhqInfo ="-"+that.dataInfo.amount_total+"元"
					}else{
						that.count = (Number(that.dataInfo.amount_total)- Number(price)).toFixed(2)
						if(price!=0){
							that.yhqInfo ="-"+price.toFixed(2)+"元"
						}
					}
					that.extra_price = 0
				}
			},
			onTab(index,d){
				let that = this
				let data = that.quanInfo
				data.map((item)=>{
					if(that.overlay_coupon==1){
						if(index.id==item.id){
							item.checked = !item.checked
						}else{
							item.checked = false
						}
					}else if(that.overlay_coupon==2&&index.id==item.id){
						item.checked = !item.checked
					}
				})
				if(that.overlay_coupon==2){
					if(index.checked){
						if((parseFloat(that.prices) + parseFloat(index.price))>that.coupon_price_max){
							that.tui.toast('已超过最大使用金额'+that.coupon_price_max+' 请重新选择')
							data[d].checked = false
							return
						}else{
							that.prices = parseFloat(that.prices) + parseFloat(index.price)
						}
					}else{
						that.prices = parseFloat(that.prices) - parseFloat(index.price)
					}
				}else if(that.overlay_coupon==1){
					that.prices =parseFloat(index.price)
				}
				
				that.quanInfo = data
				that.$forceUpdate()
			},
			onTabY(index){
				let that = this
				let data = that.quanInfoY
				if(that.overlay_couponY==2){
					if(!index.checked){
						if((parseFloat(that.priceY) + parseFloat(index.price))>that.coupon_price_max){
							that.tui.toast('已超过最大使用金额'+that.coupon_price_max+' 请重新选择')
							return
						}else{
							that.priceY = parseFloat(that.priceY) + parseFloat(index.price)
						}
					}else{
						that.priceY = parseFloat(that.priceY) - parseFloat(index.price)
					}
				}else if(that.overlay_couponY==1){
					that.priceY =parseFloat(index.price)
				}
				data.map((item)=>{
					if(that.overlay_couponY==1){
						if(index.id==item.id){
							item.checked = true
						}else{
							item.checked = false
						}
					}else if(that.overlay_couponY==2&&index.id==item.id){
						item.checked = !item.checked
					}
				})
				that.quanInfoY = data
				that.$forceUpdate()
			},
			getData(){
				let that = this
				that.tui.request("api.auth.center/get", "POST", {}, false, false, true).then((res) => {
					if (res.code == 1) {
						if(res.data.community_pid){
							that.dataInfos = res.data.community_pid
						}
						that.buy_shop_switch = res.data.buy_shop_switch
						if(res.data.username!=''){
							that.name = res.data.username
							that.isName = true
						}else{
							that.isName = false
						}
						if(res.data.phone!=''){
							that.phone = res.data.phone
							that.isPhone = true
						}else{
							that.isPhone = false
						}
						that.pay_switch = res.data.pay_switch
						that.userId = res.data.pay_new_switch
						if(that.buy_shop_switch==2){
							that.getAddress()
						}
						that.userinfo = res.data
					}
				}).catch((res) => {
				
				})
			},
			onSubmit(){
				let that = this
				if(that.isBtn){
					return
				}
				that.isBtn = true
				uni.showLoading()
				if(!that.addressInfo&&that.buy_shop_switch==2){
					that.tui.toast("请先填写收货地址")
					setTimeout(function(){
						uni.navigateTo({
							url: '/pages/AddressEdit/AddressEdit'
						})
					},1000)
					return
				}
				let zhifuNum = ''
				if(!that.tui.isValidPhoneNumber(that.phone)&&that.buy_shop_switch==1){
					that.tui.toast("手机号格式有误")
					that.isBtn = false
					return
				}
				let goods_type = that.dataInfo.goods_type
				if(that.dataInfo.goods_type==4&&that.dataInfo.amount_total!=0){
					goods_type = 2
				}
				that.tui.request("api.auth.order/perfect", "post", {order_no:that.code,code:that.addressInfo.code,coupon_id:that.yhqContent,address_name:that.name,address_phone:that.phone,extra_coupon_id:that.yhqContentY,is_extra_coupon:that.ischeck?1:2}, false,false, true).then((res) => {
					if(res.code==1){
						that.tui.request("api.auth.order/payment", "post", {order_no:res.data.order_no,payment_code:goods_type==3?'M8052888745606631252':goods_type==4?"M8219770040717089068":goods_type==2?that.userId:''}, false,false, true).then((ddd) => {
							// that.tui.toast('支付成功')
							uni.hideLoading()
							if(ddd.code==1){
								if(goods_type==3){
									that.tui.toast('支付成功')
									setTimeout(function(){
										uni.redirectTo({
											url:'/pages/PayResult/PayResult?price='+that.count+"&zhifu=礼品卡&goods_type=3",
										})
										that.isBtn = false
									},1000)
								}else if(goods_type==4){
									that.tui.toast('支付成功')
									setTimeout(function(){
										uni.redirectTo({
											url:'/pages/PayResult/PayResult?price='+that.count+"&zhifu=红包券&goods_type=3",
										})
										that.isBtn = false
									},1000)
								}else{
									if(ddd.data.type==2){
										that.tui.toast('支付成功')
										setTimeout(function(){
											uni.redirectTo({
												url:'/pages/PayResult/PayResult?price='+that.count+"&zhifu=优惠券抵扣&goods_type=1",
											})
											that.isBtn = false
										},1000)
									}else{
										// #ifdef MP
										uni.requestPayment({
											timeStamp: ddd.data.param.timeStamp,
											nonceStr: ddd.data.param.nonceStr,
											package: ddd.data.param.package,
											signType: ddd.data.param.signType,
											paySign: ddd.data.param.paySign,
										    success: function (res) {
										        console.log('success:' + JSON.stringify(res));
												setTimeout(function(){
													uni.redirectTo({
														url:'/pages/PayResult/PayResult?price='+that.count+"&zhifu=微信支付&goods_type=1",
													})
													that.isBtn = false
												},1000)
										    },
										    fail: function (err) {
										        console.log('fail:' + JSON.stringify(err));
												that.isBtn = false
										    }
										});
										// #endif
										// #ifdef H5
										console.log(res.data)
										if(that.pay_switch==5){
											
											window.location.href = ddd.data.param.url;
											
										}else if(that.pay_switch==6){
											
											uni.setStorageSync('isZhifu',ddd.data.param)
											
											window.location.href = ddd.data.param.url;
										
										}else{
											function onBridgeReady() {
												WeixinJSBridge.invoke(
													'getBrandWCPayRequest', {
														"appId": ddd.data.param.appId, //公众号名称，由商户传入     
														"timeStamp": ddd.data.param.timeStamp, //时间戳，自1970年以来的秒数     
														"nonceStr": ddd.data.param.nonceStr, //随机串     
														"package": ddd.data.param.package,
														"signType": ddd.data.param.signType, //微信签名方式：     
														"paySign": ddd.data.param.paySign, //微信签名 
													},
													function(res) {
														if (res.err_msg == "get_brand_wcpay_request:ok") {
															setTimeout(function(){
																uni.redirectTo({
																	url:'/pages/PayResult/PayResult?price='+that.count+"&zhifu=微信支付&goods_type=1",
																})
																that.isBtn = false
															},1000)
															// 使用以上方式判断前端返回,微信团队郑重提示：
															// res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
														}else{
															that.isBtn = false
														}
														
													});
											}
											if (typeof WeixinJSBridge == "undefined") {
												if (document.addEventListener) {
													document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
												} else if (document.attachEvent) {
													document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
													document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
												}
											} else {
												onBridgeReady();
											}
										}
										
										// #endif
									}
								}
								
								// setTimeout(function(){
									// uni.redirectTo({
									// 	url: '/pages/PayResult/PayResult?price='+that.price+"&zhifu="+that.PayList[that.PayWay].name,
									// })
									// uni.redirectTo({
									// 	url:'/pages/shop/order_list?type=2'
									// })
								// },1000)
							}else{
								setTimeout(function(){
									uni.redirectTo({
										url:'/pages/shop/order_list?type=1'
									})
									that.isBtn = false
								},1000)
							}
						}).catch((res) => {
							that.isBtn = false
						})
					}else{
						that.isBtn = false
					}
					
					
				}).catch((res) => {
					that.isBtn = false
				})
				
			},
			getSockt(){
				let that = this
				that.goeasy.connect({
					onSuccess: function () {  //连接成功
					  console.log("GoEasy connect successfully.") //连接成功
					},
					onFailed: function (error) { //连接失败
					  console.log("Failed to connect GoEasy, code:"+error.code+ ",error:"+error.content);
					},
					onProgress:function(attempts) { //连接或自动重连中
					  console.log("GoEasy is connecting", attempts);
					}
				});
				that.goeasy.pubsub.subscribe({
				    channel: that.code,//替换为您自己的channel
				    onMessage: function (message) {
				        //收到消息
				        console.log("Channel:" + message.channel + " content:" + message.content);
						if(message.channel==that.code){
							that.isloading =false
							that.closeGoeasy()
							uni.redirectTo({
								url:'/pages/PayResult/PayResult?price='+that.count+"&zhifu=微信支付&goods_type=1",
							})
							that.isBtn = false
						}
				    },
				    onSuccess: function () {
				        console.log("Channel订阅成功");
						that.isSocket = true
				    },
				    onFailed: function (error) {
				        console.log("Channel订阅失败, 错误编码：" + error.code + " 错误信息：" + error.content)
				    }
				});
			},
			closeGoeasy(){
				let that = this
				this.goeasy.disconnect({
					onSuccess: function(){
						console.log("GoEasy disconnect successfully.")
						that.isSocket = false
					},
					onFailed: function(error){
						console.log("Failed to disconnect GoEasy, code:"+error.code+ ",error:"+error.content);
					}
				});
			},
			getStatus(){
				let that = this
				that.tui.request("api.auth.order/orderPaymentStatus", "GET", {order_no:that.code}, false,false, true).then((res) => {
					if(res.code==1&&res.data.status==1){
						uni.setStorageSync('isZhifu','')
						uni.redirectTo({
							url:'/pages/PayResult/PayResult?price='+that.count+"&zhifu=微信支付&goods_type=1",
						})
						that.isBtn = false
					}else{
						uni.redirectTo({
							url:'/pages/MyOrderList/MyOrderList'
						})
						uni.setStorageSync('isZhifu','')
						that.isBtn = false
					}
				}).catch((res) => {})
				
			},
			getStatus1(e){
				let that = this
				that.tui.request("api.auth.order/orderPaymentStatusQueryYy", "GET", {trade_no:e.trade_no,order_no:that.code,mc_no:e.mc_no}, false,false, true).then((res) => {
					if(res.code==1&&res.data.status==1){
						uni.setStorageSync('isZhifu','')
						uni.redirectTo({
							url:'/pages/PayResult/PayResult?price='+that.count+"&zhifu=微信支付&goods_type=1",
						})
						that.isBtn = false
					}else{
						uni.redirectTo({
							url:'/pages/MyOrderList/MyOrderList'
						})
						uni.setStorageSync('isZhifu','')
						that.isBtn = false
					}
				}).catch((res) => {})
				
			},
			onConfirm(){
				this.isShow = false
				let price = this.prices
				this.yhqContent = ''
				this.quanInfo.map((item,index)=>{
					if(item.checked){
						this.yhqContent =item.id+','+this.yhqContent
					}
				})
				if(this.yhqContent == ''){
					price = 0
				}
				if(price!=0){
					if(price>=(Number(this.dataInfo.amount_total)-Number(this.extra_price))){
						this.yhqInfo ="-"+(Number(this.dataInfo.amount_total)-Number(this.extra_price)).toFixed(2)+"元"
					}else{
						this.yhqInfo ="-"+price.toFixed(2)+"元"
					}
					this.count = (Number(this.dataInfo.amount_total) - Number(price)-Number(this.extra_price)).toFixed(2)
					if(this.count<0){
						this.count = 0
					}
				}else{
					this.yhqInfo ="请选择优惠券"
					this.count =(Number(this.dataInfo.amount_total) - Number(this.extra_price)).toFixed(2)
				}
				this.getCount()
			},
			onConfirmY(){
				this.isShowY = false
				let price = this.priceY
				this.yhqContentY = ''
				this.quanInfoY.map((item,index)=>{
					if(item.checked){
						this.yhqContentY =item.id+','+this.yhqContentY
					}
				})
				if(this.yhqContentY == ''){
					price = 0
				}
				if(price!=0){
					if(price>=(Number(this.dataInfo.amount_total)-Number(this.prices))){
						this.yhqInfoY ="-"+(Number(this.dataInfo.amount_total)-Number(this.prices)).toFixed(2)+"元"
					}else{
						this.yhqInfoY ="-"+price.toFixed(2)+"元"
					}
					this.count = (Number(this.dataInfo.amount_total) -Number(price)-Number(this.prices)).toFixed(2)
					if(this.count<0){
						this.count = 0
					}
				}else{
					this.yhqInfoY ="请选择指定优惠券"
					this.count = (Number(this.dataInfo.amount_total) - Number(this.prices)).toFixed(2)
				}
				
			},
			openQuan(){
				if(this.quanInfo.length==0){
					return
				}
				this.isShow = true
			},
			openQuanY(){
				if(this.quanInfoY.length==0){
					return
				}
				this.isShowY = true
			},
			getQuan(){
				let that = this
				that.tui.request("api.auth.order/couponOrderList", "GET", {code:that.dataInfo.order[0].goods_code,number:that.dataInfo.number_goods,goods_sku:that.dataInfo.order[0].goods_spec}, false,false, true).then((res) => {
					res.data.list.map((item)=>{
						item.checked = false
					})
					that.quanInfo = res.data.list
					that.overlay_coupon = res.data.overlay_coupon
					that.coupon_price_max = res.data.coupon_price_max
					that.prices = that.dataInfo.coupon_price
					if(that.overlay_coupon==3){
						that.prices = that.dataInfo.coupon_price
					}
					that.getQuanY()
				}).catch((res) => {})
			},
			getQuanY(){
				let that = this
				that.tui.request("api.auth.order/couponOrderExtraList", "GET", {code:that.dataInfo.order[0].goods_code,number:that.dataInfo.number_goods,goods_sku:that.dataInfo.order[0].goods_spec}, false,false, true).then((res) => {
					res.data.list.map((item)=>{
						item.checked = false
					})
					that.quanInfoY = res.data.list
					that.overlay_couponY = res.data.overlay_coupon
					that.coupon_price_maxY = res.data.coupon_price_max
					that.extra_coupon_price = res.data.extra_coupon_price
					that.count = that.dataInfo.amount_total
					that.getCount()
				}).catch((res) => {})
			},
			getAddress(){
				let that = this
				that.tui.request("api.auth.address/get", "GET", {page:1}, false,false, true).then((res) => {
					that.addressInfo = res.data.list[0]
				}).catch((res) => {})
			},
			get_data(){
				let that = this
				that.tui.request("api.auth.order/orderDetail", "post", {order_no:that.code}, false, true, false).then((res) => {
					console.log(res)
					that.dataInfo = res.data.info
					that.order = res.data.info.order
					that.getQuan()
				}).catch((res) => {})
			},
			onAddress() {
				if(this.addressInfo){
					uni.navigateTo({
						url: '/pages/AddressList/AddressList'
					})
				}else{
					uni.navigateTo({
						url: '/pages/AddressEdit/AddressEdit'
					})
				}
			},
      /**
       * 跳转点击
       * @param {String} type 跳转类型
       */
      onSkip(type){
        switch (type){
          case 'address':
            uni.navigateTo({
              url: '/pages/AddressList/AddressList',
            })
            break;
        }
      }
		}
	}
</script>

<style scoped lang="scss">
	@import 'ConfirmOrder.scss';
	.zhezhao{background: rgba(0, 0, 0, .3);
		position: fixed;top: 0;left: 0;width: 100%;height: 100%;z-index: 11111;
	}
	.cu-dialog{
		width: 100%;
		border-radius: 20rpx 20rpx 0 0 !important;
		background-color: #f6f6f6 !important;
		.coupon-title{
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 4%;
			height: 100rpx;
			background-color: #FFFFFF;
			.title{
				font-size: 32rpx;
				color: #222222;
			}
			.explain{
				font-size: 26rpx;
				color: #959595;
			}
		}
		.coupon-tab{
			display: flex;
			align-items: center;
			width: 100%;
			height: 80rpx;
			background-color: #FFFFFF;
			.tab{
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 50%;
				height: 100%;
				text{
					font-size: 26rpx;
					color: #555555;
				}
				.line{
					display: none;
					position: absolute;
					left: 50%;
					bottom: 10rpx;
					width: 60rpx;
					height: 7rpx;
					background: linear-gradient(to right,$base,#f6f6f6);
					transform: translate(-50%,0);
				}
			}
			.action{
				text{
					color: #222222;
				}
				.line{
					display: block;
				}
			}
		}
		// 优惠券数据
		.coupon-data{
			padding: 20rpx 4% 100rpx;
			overflow: auto;
			.coupon-list{
				width: 100%;
				.list{
					position: relative;
					display: flex;
					align-items: center;
					width: 100%;
					height: 200rpx;
					box-shadow: 0 0 14rpx rgba(0,0,0,0.1);
					border-radius: 6rpx;
					margin-bottom: 20rpx;
					background-color: #FFFFFF;
					overflow: hidden;
					.coupon-price{
						position: relative;
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;
						width: 30%;
						height: 100%;
						background-color: $base;
						.discounts{
							display: flex;
							justify-content: center;
							align-items: flex-end;
							width: 100%;
							.min{
								color: #FFFFFF;
								font-size: 32rpx;
								font-weight: bold;
							}
							.max{
								font-size: 48rpx;
								color: #FFFFFF;
								font-weight: bold;
							}
						}
						.full-reduction{
							display: flex;
							justify-content: center;
							align-items: center;
							width: 100%;
							height: 60rpx;
							text{
								font-size: 24rpx;
								color: #FFFFFF;
							}
						}
						.jag{
							position: absolute;
							top: 0;
							left: -6rpx;
							width: 6px;
							height: 100%;
							background-size: 10px 6px;
							background-color: #fff;
							background-position: 100% 35%;
							background-image: linear-gradient(-45deg, $base 25%, transparent 25%, transparent), 
															linear-gradient(-135deg, $base 25%, transparent 25%, transparent), 
															linear-gradient(-45deg, transparent 75%, $base 75%), 
															linear-gradient(-135deg, transparent 75%, $base 75%);
						}
					}
					.coupon-info{
						position: relative;
						width: 70%;
						height: 90%;
						padding: 0 4%;
						.check{
							position: absolute;
							right: 20rpx;
							top: 50%;
							width: 50rpx;
							height: 50rpx;
							transform: translate(0,-50%);
							.iconfont{
								font-size: 36rpx;
								color: #f20;
							}
						}
						.info-title{
							display: flex;
							width: 100%;
							height: 100rpx;
							.tag{
								margin-right: 10rpx;
								text{
									padding: 4rpx 16rpx;
									color: #FFFFFF;
									background-color: $base;
									font-size: 24rpx;
									border-radius: 40rpx;
								}
							}
							.title{
								text{
									font-size: 24rpx;
									color: #212121;
								}
							}
						}
						.date-get{
							display: flex;
							align-items: center;
							justify-content: space-between;
							width: 100%;
							height: 80rpx;
							.date{
								display: flex;
								align-items: center;
								text{
									font-size: 24rpx;
									color: #555555;
								}
							}
							.get{
								text{
									padding: 10rpx 20rpx;
									background-color: $base;
									color: #FFFFFF;
									font-size: 24rpx;
									border-radius: 100rpx;
								}
								.use{
									background-color: transparent;
									border: 1px solid $base;
									color: $base;
								}
							}
						}
					}
					.use-status{
						position: absolute;
						right: -20rpx;
						top: -25rpx;
						z-index: 10;
						width: 100rpx;
						height: 100rpx;
						border: 2rpx solid #C0C0C0;
						border-radius: 100%;
						text{
							display: inline-block;
							color: #C0C0C0;
							font-size: 24rpx;
							transform: rotate(45deg);
							margin-top: 40rpx;
						}
					}
				}
				// 不可用样式
				.forbidden{
					.coupon-price{
						background-color: #CCCCCC;
						.jag{
							background-image: linear-gradient(-45deg, #CCCCCC 25%, transparent 25%, transparent),
															linear-gradient(-135deg, #CCCCCC 25%, transparent 25%, transparent), 
															linear-gradient(-45deg, transparent 75%, #CCCCCC 75%), 
															linear-gradient(-135deg, transparent 75%, #CCCCCC 75%);
						}
					}
					.coupon-info{
						.info-title{
							.title{
								text{
									color: #CCCCCC;
								}
							}
							.tag{
								text{
									background-color: #CCCCCC;
								}
							}
						}
						.date-get{
							.date{
								text{
									color: #CCCCCC;
								}
							}
						}
					}
				}
			}
		}
		// 确认
		.cpupon-confirm{
			position: absolute;
			left: 0;
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 100rpx;
			background-color: #FFFFFF;
			.confirm{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 90%;
				height: 70%;
				font-size: 26rpx;
				color: #FFFFFF;
				background-color: $base;
				border-radius: 100rpx;
			}
		}
	}
	
</style>